#include <stdio.h>
#include <stdlib.h>

typedef struct Node
{
    int data;
    struct Node* next;
}Node;

int main(int argc, char* argv[])
{
    int n = 0, k = 0;
    scanf("%d %d", &n, &k);

    struct Node* head, * prev, * temp, * p;

    head = (Node*)malloc(sizeof(Node));
    head->data = 1;
    head->next = NULL;
    temp = head;

    //create Linked List
    for (int i = 2; i <= n; i++)
    {
        p = (Node*)malloc(sizeof(Node));
        p->data = i;
        p->next = NULL;
        temp->next = p;
        temp = p;
    }
    temp->next = head;

    //solve problem
    temp = head;
    prev = head;
    while (n > 1)
    {
        for (int i = 1; i < k; i++)
        {
            prev = temp;
            temp = temp->next;
        }
        //printf("%d ",temp->data);
        prev->next = temp->next;
        free(temp);
        temp = prev->next;
        n--;
    }
    printf("%d", temp->data);
    free(temp);

    return 0;
}